import allure
from airtest.core.api import *

from common.airtest.airtest_base import AirtestBase, exists_1
from common.log.log import log
from config.conf import BASE_DIR


class RedemptionDetailsPage:
    """兑换详情页"""

    @allure.step('兑换详情页，点击立即兑换')
    def redeem_now(self):
        """
        兑换详情页，点击立即兑换
        :return:
        """
        try:
            log.info('进入兑换详情页')
            element_1 = BASE_DIR + r"/element_picture/我的/兑换优惠券页/兑换详情页/立即兑换按钮.png"
            element_2 = BASE_DIR + r"/element_picture/我的/兑换优惠券页/兑换详情页/已兑换.png"
            if exists_1(element_1):
                log.info('该优惠券未兑换，立即兑换')
                AirtestBase().click_5(element_1)
                return True
            elif exists_1(element_2):
                log.info('该优惠券已被兑换！！！')
                return False
        except Exception as e:
            log.error(f'兑换详情页，点击立即兑换过程中出现异常为：{e}')
            raise e